//
//  WBBaseController.swift
//  Weibo
//
//  Created by xu on 2017/3/18.
//  Copyright © 2017年 xuantong. All rights reserved.
//

import UIKit

class WBController: UINavigationController,UIGestureRecognizerDelegate{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置代理
         self.interactivePopGestureRecognizer?.delegate = self
        
        
        //重写push方法
        
    }

     override func pushViewController(_ viewController : UIViewController, animated: Bool){
        
            //获取所有的子控制器
            let count = childViewControllers.count
            //判断是不是根视图控制器
            if count > 0 {
                
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(back))

            }
            super.pushViewController(viewController, animated: animated)
        }
    
    @objc private func back() {
        
        popViewController(animated: true)

    }
    
    //添加手势,当设置自定义返回按钮时,(拖动返回控制器失效)
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        //判断是否是根控制器
        let count = childViewControllers.count
        
        return count > 1
        
        
    }
}
